FrameLib  0.1
Arbitrarily timed and sized frame-based DSP
FrameLib_Object.h
Go to the documentation of this file.
1 
2 #ifndef FRAMELIB_BLOCK_H
3 #define FRAMELIB_BLOCK_H
4 
5 #include "FrameLib_Types.h"
6 #include "FrameLib_Parameters.h"
7 #include "FrameLib_Info.h"
8 #include <string>
9 
10 // FrameLib_Object
11 
12 // This abstract template class outlines the basic functionality that objects (blocks / DSP / multichannel must provide)
13 
14 template <class T>
15 class FrameLib_Object : protected FrameLib_Info
16 {
17 
18 public:
19 
20  // Constructor / Destructor
21 
22  FrameLib_Object(ObjectType type) : mType(type), mNumIns(0), mNumOuts(0), mNumAudioChans(0) {}
23  virtual ~FrameLib_Object() {}
24 
25  // Object Type
26 
27  ObjectType getType() { return mType; }
28 
29  // Basic IO Setup / Queries
30 
31  void setIO(unsigned long nIns, unsigned long nOuts, unsigned long nAudioChans = 0)
32  {
33  mNumIns = (getType() == kScheduler || nIns) ? nIns : 1;
34  mNumOuts = nOuts;
35  mNumAudioChans = nAudioChans;
36  }
37 
38  unsigned long getNumIns() { return mNumIns; }
39  unsigned long getNumOuts() { return mNumOuts; }
40  unsigned long getNumAudioIns() { return getType() != kOutput ? mNumAudioChans : 0; }
41  unsigned long getNumAudioOuts() { return getType() == kOutput ? mNumAudioChans : 0; }
42  unsigned long getNumAudioChans() { return mNumAudioChans; }
43 
44  // Set Fixed Inputs
45 
46  virtual void setFixedInput(unsigned long idx, double *input, unsigned long size) = 0;
47 
48  // Audio Processing
49 
50  // Override to handle audio at the block level (reset called with the audio engine resets)
51 
52  virtual void blockUpdate(double **ins, double **outs, unsigned long blockSize) = 0;
53  virtual void reset(double samplingRate, unsigned long maxBlockSize) = 0;
54 
55  // Return to host to request to be passed audio
56 
57  static bool handlesAudio() { return false; }
58 
59  // Connections
60 
61  virtual void deleteConnection(unsigned long inIdx) = 0;
62  virtual void addConnection(T *object, unsigned long outIdx, unsigned long inIdx) = 0;
63  virtual void clearConnections() = 0;
64  virtual bool isConnected(unsigned long inIdx) = 0;
65 
66  // Info
67 
68  virtual std::string objectInfo(bool verbose = false) { return "No object info available"; }
69  virtual std::string inputInfo(unsigned long idx, bool verbose = false) { return "No input info available"; }
70  virtual std::string outputInfo(unsigned long idx, bool verbose = false) { return "No output info available"; }
71  virtual std::string audioInfo(unsigned long idx, bool verbose = false) { return "No audio channel info available"; }
72 
73  virtual FrameType inputType(unsigned long idx) = 0;
74  virtual FrameType outputType(unsigned long idx) = 0;
75 
76  // N.B. Parameter objects can be queried directly for info
77 
78  virtual const FrameLib_Parameters *getParameters() { return NULL; }
79 
80 private:
81 
82  const ObjectType mType;
83 
84  unsigned long mNumIns;
85  unsigned long mNumOuts;
86  unsigned long mNumAudioChans;
87 };
88 
89 // FrameLib_Block
90 
91 // This abstract class provides a connectivity interface to FrameLib_DSP objects or blocks (groups of FrameLib_DSP objects).
92 // Standard objects inherit this in the FrameLib_DSP class.
93 // Objects that have asynchronous outputs can use this class to host multiple FrameLib_DSP objects and connect them correctly.
94 
95 class FrameLib_Block : public FrameLib_Object<FrameLib_Block>
96 {
97 
98 public:
99 
100  // Constructor / Destructor
101 
103  virtual ~FrameLib_Block() {}
104 
105  // Connections
106 
107  virtual void addConnection(class FrameLib_DSP *object, unsigned long outIdx, unsigned long inIdx) = 0;
108 
109  virtual void addConnection(FrameLib_Block *object, unsigned long outIdx, unsigned long inIdx)
110  {
111  addConnection(object->getOutputObject(outIdx), outIdx, inIdx);
112  }
113 
114 protected:
115 
116  virtual class FrameLib_DSP *getOutputObject(unsigned long outIdx) = 0;
117 };
118 
119 #endif
ObjectType
Definition: FrameLib_Types.h:24
virtual std::string objectInfo(bool verbose=false)
Definition: FrameLib_Object.h:68
Definition: FrameLib_Parameters.h:21
unsigned long getNumIns()
Definition: FrameLib_Object.h:38
virtual void deleteConnection(unsigned long inIdx)=0
virtual const FrameLib_Parameters * getParameters()
Definition: FrameLib_Object.h:78
virtual class FrameLib_DSP * getOutputObject(unsigned long outIdx)=0
virtual ~FrameLib_Block()
Definition: FrameLib_Object.h:103
virtual void blockUpdate(double **ins, double **outs, unsigned long blockSize)=0
FrameLib_DSP * getOutputObject(unsigned long outIdx)
Definition: FrameLib_DSP.h:175
Definition: FrameLib_DSP.h:17
virtual void clearConnections()=0
virtual std::string outputInfo(unsigned long idx, bool verbose=false)
Definition: FrameLib_Object.h:70
virtual void addConnection(FrameLib_Block *object, unsigned long outIdx, unsigned long inIdx)
Definition: FrameLib_Object.h:109
Definition: FrameLib_Object.h:15
virtual void setFixedInput(unsigned long idx, double *input, unsigned long size)=0
unsigned long getNumAudioIns()
Definition: FrameLib_Object.h:40
virtual void addConnection(T *object, unsigned long outIdx, unsigned long inIdx)=0
virtual FrameType outputType(unsigned long idx)=0
unsigned long getNumAudioOuts()
Definition: FrameLib_Object.h:41
virtual std::string inputInfo(unsigned long idx, bool verbose=false)
Definition: FrameLib_Object.h:69
ObjectType getType()
Definition: FrameLib_Object.h:27
virtual FrameType inputType(unsigned long idx)=0
virtual void reset(double samplingRate, unsigned long maxBlockSize)=0
FrameLib_Object(ObjectType type)
Definition: FrameLib_Object.h:22
Definition: FrameLib_Object.h:95
virtual bool isConnected(unsigned long inIdx)=0
size_t blockSize(void *ptr)
Definition: FrameLib_Memory.cpp:23
static bool handlesAudio()
Definition: FrameLib_Object.h:57
virtual std::string audioInfo(unsigned long idx, bool verbose=false)
Definition: FrameLib_Object.h:71
void setIO(unsigned long nIns, unsigned long nOuts, unsigned long nAudioChans=0)
Definition: FrameLib_Object.h:31
virtual ~FrameLib_Object()
Definition: FrameLib_Object.h:23
FrameLib_Block(ObjectType type)
Definition: FrameLib_Object.h:102
unsigned long getNumOuts()
Definition: FrameLib_Object.h:39
Definition: FrameLib_Types.h:24
FrameType
Definition: FrameLib_Types.h:25
Definition: FrameLib_Types.h:24
unsigned long getNumAudioChans()
Definition: FrameLib_Object.h:42
Definition: FrameLib_Info.h:12